package com.cqc.manage.service.Imp.user;

import com.cqc.manage.entity.User;
import com.cqc.manage.entity.UserConnectionRole;
import com.cqc.manage.repositories.RoleRepositories;
import com.cqc.manage.repositories.UserConnRoleRepository;
import com.cqc.manage.repositories.UserRepositories;
import com.cqc.manage.util.BaseValue;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class UserConnRoleService {

    private static Logger LOG = LoggerFactory.getLogger(UserConnRoleService.class);

    @Autowired
    private UserConnRoleRepository userConnRoleRepository;

    @Autowired
    private UserRepositories userRepositories;

    @Autowired
    private RoleRepositories roleRepositories;

    /**
     * 添加用户、角色连接
     * @param
     * @return
     */
    public UserConnectionRole addUserConnRole(){

        for (String str : BaseValue.getEngName())
        {
            try {
                User userByUserName = userRepositories.findUserByUserName(str);
                UserConnectionRole userConnectionRole1 = new UserConnectionRole();
                userConnectionRole1.setUserId(userByUserName.getUserId());
                userConnectionRole1.setRoleId("712ec93ddf5f450288c0b5260cd132d3");
                userConnectionRole1.setConnectionId(UUID.randomUUID().toString().replace("-",""));
                userConnRoleRepository.save(userConnectionRole1);
            }catch (Exception e){
                System.err.println(str);
            }

        }



        return null;
    }

    /**
     * 通过用户名获取角色列表
     * @param userName
     * @return
     */
    public List<String> getRoleListByUserName(String userName){
        return null;
    }

    /**
     * 通过角色名获取用户列表
     * @param roleName
     * @return
     */
    public List<String> getUserListByRoleName(String roleName){
        return null;
    }


}
